package com.itheima.test5;

import java.util.Scanner;

public class CarTest {
    public static void main(String[] args) {
        /*定义数组存储3部汽车对象
        汽车的的属性：品牌，价格，颜色
        创建3个汽车对象，数据通过键盘录入而来，并把数据存入到数组当中
         */

        //定义数组存储对象
        Car[] carsArr = new Car[3];

        //键盘录入
        Scanner sc = new Scanner(System.in);
        //循环创建对象并录入
        for (int i = 0; i < carsArr.length; i++) {
            //创建对象
            Car c = new Car();
            //键盘录入
            System.out.println("请输入第" + (i + 1) + "辆汽车品牌");
            String brand = sc.next();
            //把数据存入对象
            c.setBrand(brand);

            System.out.println("请输入第" + (i + 1) + "辆汽车价格");
            int price = sc.nextInt();
            //把数据存入对象
            c.setPrice(price);

            System.out.println("请输入第" + (i + 1) + "辆汽车颜色");
            String color = sc.next();
            //把数据存入对象
            c.setColor(color);

            //把对象存入数组
            carsArr[i] = c;
        }


        //输出观察
        for (int i = 0; i < carsArr.length; i++) {
            Car c = carsArr[i];
            System.out.println(c.getBrand() + ", " + c.getPrice() + ", " + c.getColor());
        }
    }
}
